package com.cn.download.servlet;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

public class DownloadServlet02 extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String fileName = request.getParameter("name");
		fileName = new String(fileName.getBytes("ISO-8859-1"),"UTF-8");
		response.setContentType(getServletContext().getMimeType(fileName));
		response.setHeader("content-disposition", "attachment;filename="+DownloadUtils.encode(fileName,request));
		InputStream is = getServletContext().getResourceAsStream("/download/"+fileName);
		ServletOutputStream os = response.getOutputStream();
		IOUtils.copy(is, os);
		is.close();
		os.close();
	}

}
